import http from '../../ajax/http'
import * as url from '../../api'
const state = {
    tableData:[],
    searchData:[]
}
const actions = {
    bsGetData({commit}){
        return http({
            method:'post',
            url:url.bsGetUserData
        }).then(res=>{
            commit('addData',res.data.data)
        })
    },
    bsDelData({commit},num){
        return http({
            method:'delete',
            url:url.bsDelUserData,
            data:{
                id:num
            }
        }).then(res=>{
            console.log(res);
            
            if(res.data.code === 200){
                alert('操作成功')
                return http({
                    method:'post',
                    url:url.bsGetUserData
                }).then(res=>{
                    commit('addData',res.data.data)
                })
            }
        })
    },
    bssousuoData({commit},obj){
        let {value,region} = obj
        console.log(obj);
        state.searchData =  state.tableData.filter(item => item[region]==value) 
        console.log(state.searchData);
        
    }
}
const mutations = {
    addData(context,obj){
        state.tableData = obj
    }
}
const getters = {

}
export default {
    state,
    actions,
    mutations,
    getters
}